package com.bdq.basic.api.controller;

import cn.hutool.core.convert.Convert;
import com.bdq.basic.api.model.param.CategoryGetParam;
import com.bdq.basic.api.model.param.RegionGetParam;
import com.bdq.basic.api.model.vo.CategoryGetVO;
import com.bdq.basic.api.model.vo.RegionGetVO;
import com.bdq.basic.application.model.dto.CategoryGetAppDTO;
import com.bdq.basic.application.model.dto.RegionGetAppDTO;
import com.bdq.basic.application.model.query.CategoryGetQry;
import com.bdq.basic.application.model.query.RegionGetQry;
import com.bdq.basic.application.service.BaseAppQueryService;
import com.bdq.common.entity.common.CommonResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * bdq-basic基础相关
 *
 * @author malei
 * @date 2024-05-10 11:13
 */
@RestController
@RequestMapping("/base")
public class BaseController {

    @Resource
    private BaseAppQueryService baseAppQueryService;

    /**
     * 获取分类
     *
     * @param param
     * @return
     */
    @GetMapping("/category/get")
    public CommonResult<List<CategoryGetVO>> getCategory(@Validated CategoryGetParam param) {
        List<CategoryGetAppDTO> dtoList = baseAppQueryService.getCategory(Convert.convert(CategoryGetQry.class, param));
        return CommonResult.success(Convert.toList(CategoryGetVO.class, dtoList));
    }

    /**
     * 获取区域
     *
     * @param param
     * @return
     */
    @GetMapping("/region/get")
    public CommonResult<RegionGetVO> getRegion(@Validated RegionGetParam param) {
        RegionGetAppDTO appDTO = baseAppQueryService.getRegion(Convert.convert(RegionGetQry.class, param));
        return CommonResult.success(Convert.convert(RegionGetVO.class, appDTO));
    }
}
